﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Work7
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("这是一个输入10个数存入数组，求平均值的程序");
            double[] c = new double[10];
            for (int number = 0; number < 10; ++number)
            {
                Console.Write("请您输入第{0}个数：", number + 1);
                // string s = Console.ReadLine();
                c[number] = double.Parse(Console.ReadLine());
            }

            //利用foreach语句循环输出数组中每一个元素
            Console.Write("您输入10个数为：");
            foreach (double var in c)
            {
                Console.Write(var);  //依次读取字符串中的元素
                Console.Write(" ");

            }
            Console.WriteLine();
            double average1 = average(c);
            Console.WriteLine("您输入10个数中平均值为：{0}", average1);

            Console.ReadKey();
        }
        
        static double average(double[] c1)
        {
            double average;
            double all = 0;
            /* foreach (char var in c1)
             {
                 all = all + var;
             }*/
            for (int i = 0; i < 10; ++i)
            {
                all = all + c1[i];
            }

            average = all / c1.Length;
            return average;

        }
    }
}
